home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / mail / transpor / ifmail23.z / ifmail23 / ifmail / iflib / usleep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-04  |  1.5 KB  |  67 lines

  1. /* usleep.c
  2.  * simulate the usleep() function on machines where it isn't available
  3.  * code taken from "mgetty+sendfax" (io.c) by Gert Doering
  4.  */
  5.  
  6. #if !defined(USE_SELECT) && !defined(USE_POLL) && !defined(USE_NAP)
  7. #define USE_SELECT
  8. #endif
  9.  
  10. #ifdef USE_SELECT
  11. #undef USE_POLL
  12. #undef USE_NAP
  13. #endif
  14.  
  15. #ifdef USE_POLL
  16. #undef USE_NAP
  17. #endif
  18.  
  19. #include <sys/types.h>
  20. #include <sys/time.h>
  21. #include <stdio.h>
  22. #ifndef _NOSTDLIB_H
  23. #include <stdlib.h>
  24. #endif
  25. #include <unistd.h>
  26.  
  27. #ifdef USE_POLL
  28. # include <poll.h>
  29. /*int poll _PROTO(( struct pollfd fds[], unsigned long nfds, int timeout ));*/
  30. int poll ();
  31. #endif
  32.  
  33. #ifdef USE_SELECT
  34. # include <string.h>
  35. # if defined (linux) || defined (sun) || defined (SVR4) || \
  36.      defined (__hpux) || defined (MEIBE) || defined(sgi)
  37. #  include <sys/types.h>
  38. #  include <sys/time.h>
  39. # else
  40. #  include <sys/select.h>
  41. # endif
  42. #endif
  43.  
  44. void usleep ( unsigned long waittime )        /* wait waittime microseconds */
  45. {
  46. #ifdef USE_POLL
  47. struct pollfd sdummy;
  48.     poll( &sdummy, 0, waittime );
  49. #else
  50. #ifdef USE_NAP
  51.     nap( waittime );
  52. #else
  53. #ifdef USE_SELECT
  54.     struct timeval s;
  55.  
  56.     s.tv_sec  = waittime / 1000000;
  57.     s.tv_usec = waittime % 1000000;
  58.     select( 0, (fd_set *) NULL, (fd_set *) NULL, (fd_set *) NULL, &s );
  59.  
  60. #else                /* neither poll nor nap nor select available */
  61.     if ( waittime < 2000000 ) waittime = 2000000;    /* round up, */
  62.     sleep( waittime / 1000000);        /* a sleep of 1 may not sleep at all */
  63. #endif    /* use select */
  64. #endif    /* use nap */
  65. #endif    /* use poll */
  66. }
  67.